package com.example.mask.maskmobilesshop.utils;

import java.util.Random;

/**
 * 生成随机数工具类
 * @ClassName: RandomUtil
 * @author: Xlh
 * @date 2017年1月18日 下午6:41:59 
 */
public class RandomUtil {
	
	/**
	 * 生成指定位数数字字符串
	 * @Title: getRandomNumber
	 * @param: @param length
	 * @param: @return
	 * @return: String
	 */
	public static String getRandomNumber (int length) {
		String str = "";
		Random random = new Random();  
		for (int i = 0; i < length; i++) {
			str += String.valueOf(random.nextInt(10));  
		}
		return str;
	}
	
	/**
	 * 获取指定长度的随机字符串
	 * @Title: getRandomStr
	 * @param: @param length
	 * @param: @return
	 * @return: String
	 */
	public static String getRandomStr(int length) {
		String base = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}
}
